package br.com.projeto.dao.hql;

import java.util.ArrayList;
import java.util.List;

import org.hibernate.Session;
import org.hibernate.SessionFactory;

import br.com.projeto.sakila.bean.Address;
import br.com.projeto.sakila.bean.City;

public class CityDao {
	
	private SessionFactory sessionFactory;
	private Session session;

	public CityDao(SessionFactory sessionFactory) {
		this.sessionFactory = sessionFactory;
	}
	
	public long buscarCity(){
		long tempoInicial = System.currentTimeMillis();
		
		List<City> listaCity = new ArrayList<>();
		try{
			session = sessionFactory.openSession();
			 
			listaCity = session.createQuery("from City").list();
			
			session.close();
		} catch (Exception e){
			System.err.println("Erro ");
		}
		
		long tempoFinal = System.currentTimeMillis(); 
		long tempo = tempoFinal - tempoInicial;
		return tempo;
	}
	
	public void listarCity(List<City> lista){
		System.out.println("---------------------------");
		for (City city : lista) {
			System.out.println("id : " + city.getId());
			System.out.println("city Member : " + city.getCityMember());
			System.out.println("--- Country ---");
			System.out.println("--- ID COUNTRY : "+ city.getCountry().getId());
			System.out.println("--- CITY MEMBER : "+ city.getCityMember());
			//TODO: rever
//			System.out.println("--- MEMBER COUNTRY : "+ city.getCountry().getCountryMember());
			//TODO: em country falta listcity
			//TODO: falta list address

			System.out.println("---------------------------");
		}
	}

}
